﻿CREATE TABLE [dbo].[Quote] (
    [QuoteId]               UNIQUEIDENTIFIER NOT NULL,
    [Name]                  NVARCHAR (300)   NULL,
    [OpportunityId]         UNIQUEIDENTIFIER NULL,
    [QuoteNumber]           NVARCHAR (100)   NULL,
    [StageCode]             INT              NULL,
    [OwnerId]               UNIQUEIDENTIFIER NULL,
    [ExpiresOn]             DATETIME         NULL,
    [PaymentTermsCode]      INT              NULL,
    [CreatedById]           UNIQUEIDENTIFIER NULL,
    [CreatedOn]             DATETIME         NULL,
    [ModifiedById]          UNIQUEIDENTIFIER NULL,
    [ModifiedOn]            DATETIME         NULL,
    [StatusCode]            INT              NULL,
    [CustomerId]            UNIQUEIDENTIFIER NULL,
    [Description]           NVARCHAR (MAX)   NULL,
    [TotalAmount]           MONEY            NULL,
    [TotalTax]              MONEY            NULL,
    [TotalDiscountAmount]   MONEY            NULL,
    [TotalLineItemAmount]   MONEY            NULL,
    [TransactionCurrencyId] UNIQUEIDENTIFIER NULL,
    [ExchangeRate]          DECIMAL (23, 10) NULL,
    [BillTo_AddressId]      UNIQUEIDENTIFIER NULL,
    [BillTo_ContactName]    NVARCHAR (150)   NULL,
    [VersionNumber]         ROWVERSION       NULL,
    [IsDeleted]             BIT              CONSTRAINT [DF_Quote_IsDeleted] DEFAULT ((0)) NOT NULL,
    CONSTRAINT [PK_Quote] PRIMARY KEY CLUSTERED ([QuoteId] ASC),
    CONSTRAINT [FK_Quote_Account] FOREIGN KEY ([CustomerId]) REFERENCES [dbo].[Account] ([AccountId]),
    CONSTRAINT [FK_Quote_CustomerAddress] FOREIGN KEY ([BillTo_AddressId]) REFERENCES [dbo].[CustomerAddress] ([CustomerAddressId]),
    CONSTRAINT [FK_Quote_Opportunity] FOREIGN KEY ([OpportunityId]) REFERENCES [dbo].[Opportunity] ([OpportunityId]),
    CONSTRAINT [FK_Quote_TransactionCurrency] FOREIGN KEY ([TransactionCurrencyId]) REFERENCES [dbo].[TransactionCurrency] ([TransactionCurrencyId]),
    CONSTRAINT [FK_Quote_User] FOREIGN KEY ([OwnerId]) REFERENCES [dbo].[User] ([UserId]),
    CONSTRAINT [FK_Quote_User_CreatedBy] FOREIGN KEY ([CreatedById]) REFERENCES [dbo].[User] ([UserId]),
    CONSTRAINT [FK_Quote_User_ModifiedBy] FOREIGN KEY ([ModifiedById]) REFERENCES [dbo].[User] ([UserId])
);

